/**
 * Utility functions for loading demo components
 */

// 缓存已加载的组件
const componentCache = new Map();

/**
 * Load a demo component by path
 * @param {string} componentPath - The path to the component
 * @returns {Promise<Component>} - The loaded component
 */
export async function loadDemoComponent(componentPath) {
  // 如果组件已缓存，直接返回
  if (componentCache.has(componentPath)) {
    return componentCache.get(componentPath);
  }

  try {
    // 动态导入组件
    /* eslint-disable-next-line */
    const component = await import(`../${componentPath}`);
    // 缓存组件
    componentCache.set(componentPath, component);
    return component;
  } catch (error) {
    console.error(`Error loading component from ${componentPath}:`, error);
    throw error;
  }
}

/**
 * Clear the component cache
 */
export function clearComponentCache() {
  componentCache.clear();
}

export default {
  loadDemoComponent,
  clearComponentCache
};